---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Severity/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 20:51:37

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Severity";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Severity

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Saturday, May 23, 2015                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. ** Need Legend for Probabilities and Differences  **;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Severity/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 h
> i5
>                 diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2 
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31  prob_hat41 lo41 hi41
>  prob_hat51 lo51 hi51
>                 diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>                 delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2
>                 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=-1 ;

. while `a' < 4 { ;
  2. {;
  3. scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_Parliament = 0;
  9. scalar h_CivilWar = 0;
 10. scalar h_GDPpc =  12589.35;
 11. scalar h_Growth = 3.453132;
 12. scalar h_MajorPower = 0;
 13. scalar h_Borders = 2;
 14. scalar h_Mobilization =  -.0008714 ;
 15. scalar h_Time = 5;
 16.  scalar h_Rivalry = 0;
 17. scalar h_Female = 0;
 18. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 19. generate x_betahat1 = MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 20. gen prob0=  1/(1+exp(x_betahat0-MG_b11));
 21. gen prob1=   (1/(1+exp(x_betahat0-MG_b12)))  -  (1/(1+exp(x_betahat0-MG_b11)))  ;
 22. gen prob2=   1- (1/(1+exp(x_betahat0-MG_b12)));
 23. gen prob3=  1/(1+exp(x_betahat1-MG_b11));
 24. gen prob4=  (1/(1+exp(x_betahat1-MG_b12)))  -  (1/(1+exp(x_betahat1-MG_b11)))  ;
 25. gen prob5=   1- (1/(1+exp(x_betahat1-MG_b12)));
 26.         gen diff0=prob3-prob0 ;
 27. gen diff1=prob4-prob1 ;
 28. gen diff2=prob5-prob2 ;
 29.         egen probhat0=mean(prob0) ;
 30. egen probhat1=mean(prob1) ;
 31. egen probhat2=mean(prob2) ;
 32. egen probhat3=mean(prob3) ;
 33. egen probhat4=mean(prob4) ;
 34. egen probhat5=mean(prob5) ;
 35. egen diffhat0=mean(diff0) ;
 36. egen diffhat1=mean(diff1) ;
 37. egen diffhat2=mean(diff2) ;
 38.  generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 39.  generate x_betahat11 =   MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 40. gen prob01=  1/(1+exp(x_betahat01-MG_b11));
 41. gen prob11=   (1/(1+exp(x_betahat01-MG_b12)))  -  (1/(1+exp(x_betahat01-MG_b11)))  ;
 42. gen prob21=   1- (1/(1+exp(x_betahat01-MG_b12)));
 43. gen prob31=  1/(1+exp(x_betahat11-MG_b11));
 44. gen prob41=  (1/(1+exp(x_betahat11-MG_b12)))  -  (1/(1+exp(x_betahat11-MG_b11)))  ;
 45. gen prob51=   1- (1/(1+exp(x_betahat11-MG_b12)));
 46.         gen diff01=prob31-prob01 ;
 47. gen diff11=prob41-prob11 ;
 48. gen diff21=prob51-prob21 ;
 49.         egen probhat01=mean(prob01) ;
 50. egen probhat11=mean(prob11) ;
 51. egen probhat21=mean(prob21) ;
 52. egen probhat31=mean(prob31) ;
 53. egen probhat41=mean(prob41) ;
 54. egen probhat51=mean(prob51) ;
 55. egen diffhat01=mean(diff01) ;
 56. egen diffhat11=mean(diff11) ;
 57. egen diffhat21=mean(diff21) ;
 58.         gen delta= diff01-diff0 ;
 59. gen delta1 = diff11-diff1 ;
 60. gen delta2 = diff21-diff2 ;
 61. egen deltahat=mean(delta) ;
 62. egen deltahat1=mean(delta1) ;
 63. egen deltahat2=mean(delta2) ;
 64. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 hi5
>         diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2
>         prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31 prob_hat41 lo41 hi41 prob_hat
> 51 lo51 hi51
>         diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>         delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2;
 65.             _pctile prob0, p(2.5,97.5) ;
 66.     scalar `lo0'=r(r1) ;
 67.     scalar `hi0'=r(r2) ;
 68.     _pctile prob1, p(2.5,97.5) ;
 69.     scalar `lo1'=r(r1) ;
 70.     scalar `hi1'=r(r2) ;
 71.     _pctile prob2, p(2.5,97.5) ;
 72.     scalar `lo2'=r(r1) ;
 73.     scalar `hi2'=r(r2) ;
 74.     _pctile prob3, p(2.5,97.5) ;
 75.     scalar `lo3'=r(r1) ;
 76.     scalar `hi3'=r(r2) ;
 77.     _pctile prob4, p(2.5,97.5) ;
 78.     scalar `lo4'=r(r1) ;
 79.     scalar `hi4'=r(r2) ;
 80.     _pctile prob5, p(2.5,97.5) ;
 81.     scalar `lo5'=r(r1) ;
 82.     scalar `hi5'=r(r2) ;
 83.             _pctile diff0, p(2.5,97.5) ;
 84.     scalar `diff_lo0'= r(r1) ;
 85.     scalar `diff_hi0'=r(r2) ;
 86.     _pctile diff1, p(2.5,97.5) ;
 87.     scalar `diff_lo1'= r(r1) ;
 88.     scalar `diff_hi1'=r(r2) ;
 89.     _pctile diff2, p(2.5,97.5) ;
 90.     scalar `diff_lo2'= r(r1) ;
 91.     scalar `diff_hi2'=r(r2) ;
 92.             scalar `prob_hat0'=probhat0 ;
 93.     scalar `prob_hat1'=probhat1 ;
 94.     scalar `prob_hat2'=probhat2 ;
 95.     scalar `prob_hat3'=probhat3 ;
 96.     scalar `prob_hat4'=probhat4 ;
 97.     scalar `prob_hat5'=probhat5 ;
 98.           scalar `diff_hat0'=diffhat0 ;
 99.     scalar `diff_hat1'=diffhat1 ;
100.     scalar `diff_hat2'=diffhat2 ;
101.     _pctile prob01, p(2.5,97.5) ;
102.     scalar `lo01'=r(r1) ;
103.     scalar `hi01'=r(r2) ;
104.     _pctile prob11, p(2.5,97.5) ;
105.     scalar `lo11'=r(r1) ;
106.     scalar `hi11'=r(r2) ;
107.     _pctile prob21, p(2.5,97.5) ;
108.     scalar `lo21'=r(r1) ;
109.     scalar `hi21'=r(r2) ;
110.     _pctile prob31, p(2.5,97.5) ;
111.     scalar `lo31'=r(r1) ;
112.     scalar `hi31'=r(r2) ;
113.             _pctile prob41, p(2.5,97.5) ;
114.     scalar `lo41'=r(r1) ;
115.     scalar `hi41'=r(r2) ;
116.     _pctile prob51, p(2.5,97.5) ;
117.     scalar `lo51'=r(r1) ;
118.     scalar `hi51'=r(r2) ;
119.             _pctile diff01, p(2.5,97.5) ;
120.     scalar `diff_lo01'= r(r1) ;
121.     scalar `diff_hi01'=r(r2) ;
122.     _pctile diff11, p(2.5,97.5) ;
123.     scalar `diff_lo11'= r(r1) ;
124.     scalar `diff_hi11'=r(r2) ;
125.     _pctile diff21, p(2.5,97.5) ;
126.     scalar `diff_lo21'= r(r1) ;
127.     scalar `diff_hi21'=r(r2) ;
128.     scalar `prob_hat01'=probhat01 ;
129.     scalar `prob_hat11'=probhat11 ;
130.     scalar `prob_hat21'=probhat21 ;
131.     scalar `prob_hat31'=probhat31 ;
132.     scalar `prob_hat41'=probhat41 ;
133.     scalar `prob_hat51'=probhat51 ;
134.     scalar `diff_hat01'=diffhat01 ;
135.     scalar `diff_hat11'=diffhat11 ;
136.     scalar `diff_hat21'=diffhat21 ;
137.     _pctile delta, p(2.5,97.5) ;
138.     scalar `delta_lo'= r(r1) ;
139.     scalar `delta_hi'=r(r2) ;
140.     _pctile delta1, p(2.5,97.5) ;
141.     scalar `delta_lo1'= r(r1) ;
142.     scalar `delta_hi1'=r(r2) ;
143.     _pctile delta2, p(2.5,97.5) ;
144.     scalar `delta_lo2'= r(r1) ;
145.     scalar `delta_hi2'=r(r2) ;
146.             scalar `delta_hat'=deltahat;
147.     scalar `delta_hat1'=deltahat1;
148.     scalar `delta_hat2'=deltahat2;
149.  post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
>         (`prob_hat3') (`lo3') (`hi3') (`prob_hat4') (`lo4') (`hi4') (`prob_hat5') (`lo5') (`hi5')
>         (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1') (`diff_hat2') (`diff_lo2') (`diff
> _hi2')
>         (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11') (`prob_hat21') (`lo21') (`hi21')
>         (`prob_hat31') (`lo31') (`hi31') (`prob_hat41') (`lo41') (`hi41') (`prob_hat51') (`lo51') (`hi51')
>         (`diff_hat01') (`diff_lo01') (`diff_hi01') (`diff_hat11') (`diff_lo11') (`diff_hi11') (`diff_hat21') (`diff_lo21'
> ) (`diff_hi21')
>                 (`delta_hat') (`delta_lo') (`delta_hi') (`delta_hat1') (`delta_lo1') (`delta_hi1') (`delta_hat2') (`delta
> _lo2') (`delta_hi2')
> 
>     ;
150.     } ;
151. drop    x_betahat0 x_betahat1
>         prob0 prob1 prob2 prob3 prob4 prob5
>         diff0 diff1 diff2
>         probhat0 probhat1 probhat2 probhat3 probhat4 probhat5
>         diffhat0 diffhat1 diffhat2
>         x_betahat01 x_betahat11
>         prob01 prob11 prob21 prob31 prob41 prob51
>         diff01 diff11 diff21
>         probhat01 probhat11 probhat21 probhat31 probhat41 probhat51
>         diffhat01 diffhat11 diffhat21
>         delta deltahat delta1 deltahat1 delta2 deltahat2;
152.     local a=`a'+ 1 ;
153.     display "." _c ;
154.     } ;
.....
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. gen ruler = _n;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         5    .9373631      .02442   .9026553   .9640901
         lo0 |         5    .9069763    .0380486   .8481978   .9425492
         hi0 |         5    .9603025    .0145436   .9430333   .9791934
   prob_hat1 |         5    .0481495    .0184509   .0278458    .074264
         lo1 |         5     .030362    .0110255   .0160854   .0434362
-------------+--------------------------------------------------------
         hi1 |         5    .0716585    .0286191   .0447064    .115669
   prob_hat2 |         5    .0144874    .0059704   .0080641   .0230807
         lo2 |         5    .0086763    .0033001   .0044738   .0126828
         hi2 |         5     .022817    .0100489   .0135219   .0384625
   prob_hat3 |         5    .9609362    .0228202   .9263942   .9833463
-------------+--------------------------------------------------------
         lo3 |         5     .926931    .0516459   .8415388   .9648772
         hi3 |         5    .9815556    .0082599   .9734448   .9931077
   prob_hat4 |         5    .0301543    .0174064   .0129568   .0563998
         lo4 |         5    .0142037    .0063215   .0053666   .0204004
         hi4 |         5    .0561367    .0390253   .0268845   .1202937
-------------+--------------------------------------------------------
   prob_hat5 |         5    .0089095    .0054152   .0036969    .017206
         lo5 |         5    .0039921    .0018423   .0014494   .0058252
         hi5 |         5    .0174393    .0128551    .008135   .0388403
   diff_hat0 |         5    .0235731    .0028603   .0192562   .0266238
    diff_lo0 |         5    -.013049    .0290991  -.0635242   .0065778
-------------+--------------------------------------------------------
    diff_hi0 |         5    .0573571    .0216123   .0417866   .0929864
   diff_hat1 |         5   -.0179953    .0020767  -.0201976  -.0148891
    diff_lo1 |         5   -.0436795    .0157286  -.0696208  -.0323765
    diff_hi1 |         5    .0096234    .0215131   -.005031   .0468845
   diff_hat2 |         5   -.0055779    .0008036  -.0064262  -.0043671
-------------+--------------------------------------------------------
    diff_lo2 |         5   -.0141484    .0060153  -.0240584   -.009709
    diff_hi2 |         5    .0033777    .0074799  -.0015242   .0164189
  prob_hat01 |         5    .9373631      .02442   .9026553   .9640901
        lo01 |         5    .9069763    .0380486   .8481978   .9425492
        hi01 |         5    .9603025    .0145436   .9430333   .9791934
-------------+--------------------------------------------------------
  prob_hat11 |         5    .0481495    .0184509   .0278458    .074264
        lo11 |         5     .030362    .0110255   .0160854   .0434362
        hi11 |         5    .0716585    .0286191   .0447064    .115669
  prob_hat21 |         5    .0144874    .0059704   .0080641   .0230807
        lo21 |         5    .0086763    .0033001   .0044738   .0126828
-------------+--------------------------------------------------------
        hi21 |         5     .022817    .0100489   .0135219   .0384625
  prob_hat31 |         5    .9609362    .0228202   .9263942   .9833463
        lo31 |         5     .926931    .0516459   .8415388   .9648772
        hi31 |         5    .9815556    .0082599   .9734448   .9931077
  prob_hat41 |         5    .0301543    .0174064   .0129568   .0563998
-------------+--------------------------------------------------------
        lo41 |         5    .0142037    .0063215   .0053666   .0204004
        hi41 |         5    .0561367    .0390253   .0268845   .1202937
  prob_hat51 |         5    .0089095    .0054152   .0036969    .017206
        lo51 |         5    .0039921    .0018423   .0014494   .0058252
        hi51 |         5    .0174393    .0128551    .008135   .0388403
-------------+--------------------------------------------------------
  diff_hat01 |         5    .0235731    .0028603   .0192562   .0266238
   diff_lo01 |         5    -.013049    .0290991  -.0635242   .0065778
   diff_hi01 |         5    .0573571    .0216123   .0417866   .0929864
  diff_hat11 |         5   -.0179953    .0020767  -.0201976  -.0148891
   diff_lo11 |         5   -.0436795    .0157286  -.0696208  -.0323765
-------------+--------------------------------------------------------
   diff_hi11 |         5    .0096234    .0215131   -.005031   .0468845
  diff_hat21 |         5   -.0055779    .0008036  -.0064262  -.0043671
   diff_lo21 |         5   -.0141484    .0060153  -.0240584   -.009709
   diff_hi21 |         5    .0033777    .0074799  -.0015242   .0164189
   delta_hat |         5           0           0          0          0
-------------+--------------------------------------------------------
    delta_lo |         5           0           0          0          0
    delta_hi |         5           0           0          0          0
  delta_hat1 |         5           0           0          0          0
   delta_lo1 |         5           0           0          0          0
   delta_hi1 |         5           0           0          0          0
-------------+--------------------------------------------------------
  delta_hat2 |         5           0           0          0          0
   delta_lo2 |         5           0           0          0          0
   delta_hi2 |         5           0           0          0          0
       ruler |         5           3    1.581139          1          5

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Severity/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 20:51:38
---------------------------------------------------------------------------------------------------------------------------
